<% /* $Id: header.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.security.Principal" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.lang.reflect.Field" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Collections" %>

<%@ page import="org.apache.commons.lang.StringEscapeUtils" %>

<%@ page import="alt.djudge.frontend.server.datatypes.*" %>
<%@ page import="alt.djudge.frontend.server.datatypes.scores.*" %>
<%@ page import="alt.djudge.frontend.server.datatypes.custom.*" %>
<%@ page import="alt.djudge.frontend.server.models.*" %>
<%@ page import="alt.djudge.frontend.server.models.scores.*" %>
<%@ page import="alt.djudge.frontend.server.gui.*"%>
<%@ page import="alt.djudge.frontend.server.utils.*" %>
<%@ page import="alt.djudge.frontend.server.Deployment" %>
<%@ page import="alt.djudge.frontend.server.HibernateUtil" %>
<%@ page import="alt.djudge.frontend.server.servlets.DJudgeUtils" %> 
<%@ page import="alt.djudge.frontend.server.servlets.AbstractServlet" %>
<%@ page import="alt.djudge.frontend.server.servlets.AbstractDataServlet" %>

<%
	try
	{
		Long refreshInterval = Long.parseLong(request.getParameter("refresh"));
		response.setHeader("Refresh", "" + refreshInterval);
	}
	catch(Exception e) {}
	
	StringBuffer requestUrlBuffer = new StringBuffer(request.getRequestURL().toString());
	boolean fFirst = true;
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements(); )
    {
    	String paramName = e.nextElement().toString();
    	if (!"setlocale".equals(paramName) && !"msg".equals(paramName))
    	{
	        requestUrlBuffer.append(fFirst ? '?' : '&');
	        requestUrlBuffer.append(paramName);
	        requestUrlBuffer.append('=');
	        requestUrlBuffer.append(URLEncoder.encode(request.getParameter(paramName), AbstractDataServlet.defaultEncoding));
	        fFirst = false;
    	}
    }
	String requestUrl = requestUrlBuffer.toString();
	String requestUrlEncoded = URLEncoder.encode(requestUrl, AbstractDataServlet.defaultEncoding);
	Map<String, Object> filter = new HashMap<String, Object>();
%>


<html>
	<head>
		<title>DJudge Web Frontend</title>
		<meta name="description" content="DJudge">
		<meta name="keywords" content="ACM, ICPC, IOI, algorithm, olympiad, judge, DJudge, online, problem set, programming, contest, topcoder">	
	</head>
<body>
<%

	String msg = request.getParameter("msg");
	Long pageGenerationStarted = new Date().getTime();

	UserEntry user = UsersModel.getCurrentUser(request);
	
//	ResourceBundle bundle = LocalizationModel.getResourceBundle(user != null ? LocalizationModel.getUserLocale(user, request) : LocalesModel.getDefaultEntry());

	LocaleEntry localeEntry = new LocaleEntry();
	localeEntry.setJavaLocale("en");
	ResourceBundle bundle = LocalizationModel.getResourceBundle(localeEntry);	
	
/*	// FIXME: TEMP
	if (!request.getRequestURI().toString().endsWith("login.jsp") && (user == null || !user.isAdmin()))
	{
		//response.sendRedirect(Linker.linkCurrent(""));
		response.sendError(HttpServletResponse.SC_FORBIDDEN, "You are not allowed to access administrator's area");
		return;
	}*/
	
	if (request.getRequestURI().toString().contains("/admin/") && (user == null || !user.isAdmin()))
	{
		response.sendError(HttpServletResponse.SC_FORBIDDEN, "You are not allowed to access administrator's area");
		return;
	}
	
	ContestEntry contest = ContestsModel.getEntry(1L);
%>

<!-- User menu  -->
<table>
<tr>
	<td width="100"><a href="<%= Linker.link("") %>"><%= bundle.getString("W_HOME") %></a></td>
	<td width="100"><a href="<%= Linker.link("problems.jsp") %>"><%= bundle.getString("W_PROBLEMS") %></a></td>
	<td width="100"><a href="<%= Linker.link("contests/index.jsp") %>"><%= bundle.getString("W_CONTESTS") %></a></td>
	<td width="100"><a href="<%= Linker.link("monitor.jsp") %>"><%= bundle.getString("W_MONITOR") %></a></td>
	<td width="150"><a href="<%= Linker.link("submit.jsp") %>"><%= bundle.getString("W_SUBMIT") %></a></td>
	<td width="200"><a href="<%= Linker.link("submissions.jsp") %>"><%= bundle.getString("W_SUBMISSIONS") %></a></td>
<%
	if (null != user)
	{
%>
	<td width="60" align="right"><a href="<%= Linker.link("profile.jsp") %>"><%= bundle.getString("W_PROFILE") %></a></td>
	<td width="100" align="right"><a href="<%= Linker.link("login?action=logout") %>"><%= bundle.getString("W_LOGOUT") %></a></td>
<%
	}
	else
	{
%>
	<td width="300" align="right">
		<a href="<%= Linker.link("login.jsp") %>"><%= bundle.getString("W_LOGIN") %></a>/
		<a href="<%= Linker.link("register.jsp") %>"><%= bundle.getString("W_REGISTER") %></a><br />
	</td>
	
<%
	}
%>	
</tr>
</table><hr/>


<%
	if (null != user && user.isAdmin())
	{
		String paramValue;

		if ((paramValue = request.getParameter("contestId")) != null)
			filter.put("contestId", Long.parseLong(paramValue));
		if ((paramValue = request.getParameter("contestProblemId")) != null)
			filter.put("contestProblemId", Long.parseLong(paramValue));
		if ((paramValue = request.getParameter("languageId")) != null)
			filter.put("languageId", Long.parseLong(paramValue));
		if ((paramValue = request.getParameter("problemId")) != null)
			filter.put("problemId", Long.parseLong(paramValue));
		if ((paramValue = request.getParameter("userId")) != null)
			filter.put("userId", Long.parseLong(paramValue));
		if ((paramValue = request.getParameter("active")) != null)
			filter.put("active", Boolean.parseBoolean(paramValue));
		
		if ((paramValue = request.getParameter("page")) != null)
			filter.put("page", Integer.parseInt(paramValue));
		if ((paramValue = request.getParameter("count")) != null)
			filter.put("count", Integer.parseInt(paramValue));
		
		if ((paramValue = request.getParameter("order")) != null)
			filter.put("order", paramValue);
%>
<!-- Admin menu  -->
<div class="admin_menu">
	Admin area &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/monitor.jsp") %>">Monitor</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/monitor_acm.jsp") %>">Monitor ACM</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/problems.jsp") %>">Problems</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/languages.jsp") %>">Langs</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/contestlanguages.jsp") %>">ContestLangs</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/submissions.jsp") %>">Submissions</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/pages.jsp") %>">Pages</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/contests.jsp") %>">Contests</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/contestproblems.jsp") %>">ContestProblems</a> &nbsp; &nbsp;
	<a href="<%= Linker.link("admin/users.jsp") %>">Users</a>
	<a href="<%= Linker.link("admin/sessions.jsp") %>">Sessions</a>
	<a href="<%= Linker.link("admin/contestusers.jsp") %>">ContestUsers</a>
	<a href="<%= Linker.link("admin/contestproblemstatus.jsp") %>">CPS</a>
	<a href="<%= Linker.link("stats.jsp") %>">Stats</a>
</div><hr />

<%
	}
	if (null != msg)
	{
%>
	<div align="center"><font color="red"><%= msg %></font></div>
	
<%
	}
	
	
%>

<%
	Long pageGenerationHeaderFinished = new Date().getTime();
%>

<!-- <%= "" + ((pageGenerationHeaderFinished - pageGenerationStarted)) + " ms" %>  -->
